package org.example.cet.demos.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.example.cet.demos.domain.PageBean;
import org.example.cet.demos.domain.dto.PaperDto;
import org.example.cet.demos.domain.dto.QuestionDto;
import org.example.cet.demos.domain.dto.QuestionsDto;
import org.example.cet.demos.domain.po.Questions;
import org.example.cet.demos.domain.query.QuestionsQuery;
import org.example.cet.demos.mapper.QuestionsMapper;
import org.example.cet.demos.service.IQuestionsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author hq
 * @since 2024-12-18
 */
@Service
@RequiredArgsConstructor

public class QuestionsServiceImpl extends ServiceImpl<QuestionsMapper, Questions> implements IQuestionsService {

    public PageBean getPage(QuestionsQuery questionsQuery) {
        Page<Questions> page = new Page<>(questionsQuery.getCurrentPage(), questionsQuery.getPageSize());
        lambdaQuery().like(Questions::getId, questionsQuery.getId())
                .like(!StrUtil.isBlankIfStr(questionsQuery.getType()), Questions::getType, questionsQuery.getType())
//                .like(!StrUtil.isBlankIfStr(questionsQuery.getContent()), Questions::getContent, questionsQuery.getContent())
                .page(page);
        PageBean pageBean = new PageBean();
        pageBean.setTotal(page.getTotal());
        pageBean.setRows(page.getRecords());
        return pageBean;
    }

//    @Autowired
//    private QuestionsMapper questionsMapper;
//    @Override
//    public List<T> getList(Integer type){
//        return questionsMapper.getList(type);
//    }
    @Autowired
    private QuestionsMapper questionsMapper;
    @Override
    public List<Map<String,Object>> getTypeList(Integer type) {
        return questionsMapper.getTypeList(type);
    }
    @Override
    public List<Questions> getTypeTitleList(Integer type){
        return questionsMapper.getTypeTitleList(type);
    }

    @Override
    public QuestionDto getQuestion(Integer id){
        return questionsMapper.getQuestion(id);
    }
}
